package com.order.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@Slf4j
public class OrderMQMsgConfig {

    /**
     * 分单处理队列
     */
    public static final String QUEUE_NAME_TRANSACTION = "xucheng.distribute.queue";
    
    /**
     * 分单处理交换机
     */
    public static final String EXCHANGE_NAME_TRANSACTION = "xucheng.distribute.exchange";
    
    /**
     * 消息队列服务进程，此进程包括两个部分：Exchange和Queue。
     */
    public static final String ROUTE_NAME_TRANSACTION = "xucheng.distribute.route";
    
    
    /**
     * 补单队列
     */
    //public static final String CREATE_QUEUE_NAME_TRANSACTION = "xucheng.order.reCreate.queue";
 
    /**
     * 1、交换机绑定到分单队列
     * @return
     */
     @Bean
     public DirectExchange transExchange() {
         return new DirectExchange(EXCHANGE_NAME_TRANSACTION);
     }

    /**
     *2、分单队列
     *
     * @return
     */
    @Bean
    public Queue scoreQueue() {
        return new Queue(QUEUE_NAME_TRANSACTION, true);
    }
   
     /**
      * 3、Binding
      * @return
      */
    @Bean
    public Binding bindingExchangeOrderReceiverQueue() {
    	//通过Binding将Exchange与Queue关联起来。　　
        return BindingBuilder.bind(scoreQueue()).to(transExchange()).with(ROUTE_NAME_TRANSACTION);
    }

    /**
     * 补单队列
     *
     * @return

    @Bean
    public Queue createOrderReceiver() {
        return new Queue(CREATE_QUEUE_NAME_TRANSACTION, true);
    }     */

 

   

    /**
     * 交换机绑定到补单队列
     * @return
     
    @Bean
    public Binding bindingExchangeCreateOrderQueue() {
        return BindingBuilder.bind(createOrderReceiver()).to(transExchange()).with(ROUTE_NAME_TRANSACTION);
    }*/
}
